// Load the RTCPeerConnection polyfill to support WebRTC in Safari and Internet Explorer      
var webRtcServer      = null;
    window.onload         = function() { 
    webRtcServer      = new WebRtcStreamer("video","http:"+"//"+"127.0.0.1"+":8000");
    webRtcServer.connect("rtsp://admin:yjzn123456@192.168.2.64:554");
}
window.onbeforeunload = function() { webRtcServer.disconnect(); }

function setCamRtspUrl() {
    var url = document.getElementById("cam_rtsp_url").value;
    if (url == "") {
        alert("Please enter the RTSP url of the camera.");
        return;
    }
    if (webRtcServer != null) {
        webRtcServer.disconnect();
    }
    webRtcServer.connect(url);
}

document.getElementById("play").addEventListener("click", async ()=> {
    await setCamRtspUrl();
});